package com.zzptc.easyshop.servlet;

import com.sun.xml.internal.bind.v2.model.core.ID;
import com.zzptc.easyshop.dao.GoodTypeDaoImp;
import com.zzptc.easyshop.dao.IDAO;
import com.zzptc.easyshop.dao.ProductDao;
import org.omg.PortableServer.LIFESPAN_POLICY_ID;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.Principal;
import java.sql.SQLException;
import java.util.List;

@WebServlet(name = "FirstServlet")
public class FirstServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = response.getWriter();
//        pw.print("=======holle=======");
        //未使用工厂模式
        IDAO dao = new GoodTypeDaoImp();//所有商品类型
        IDAO daotype = new ProductDao();//所有商品
        List listgoodtyoe =null;

        List list =null;

        try {
            list =dao.getAll();   //dao有getAll方法
            listgoodtyoe = daotype.getAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //跳转     //转发
        request.setAttribute("alltype",list);
        request.setAttribute("product1",listgoodtyoe);

        request.getRequestDispatcher("index.jsp").forward(request,response);

        //显示所有商品  去UserDao获取所有商品  转到心事所有的商品   index.jsp


    }
}
